import request from '../request'
import type { ApiResponse, Post, CreatePostParams, UpdatePostParams, PaginationParams, PaginationResponse } from '../types'

export const postApi = {
    // 获取帖子列表
    getPosts(params: PaginationParams) {
        return request.get<ApiResponse<PaginationResponse<Post>>>('/api/posts', { params })
    },

    // 获取帖子详情
    getPostDetail(id: string) {
        return request.get<ApiResponse<Post>>(`/api/posts/${id}`)
    },

    // 创建帖子
    createPost(data: CreatePostParams) {
        return request.post<ApiResponse<Post>>('/api/posts', data)
    },

    // 更新帖子
    updatePost(data: UpdatePostParams) {
        return request.put<ApiResponse<Post>>(`/api/posts/${data.id}`, data)
    },

    // 删除帖子
    deletePost(id: string) {
        return request.delete<ApiResponse<null>>(`/api/posts/${id}`)
    },

    // 点赞帖子
    likePost(id: string) {
        return request.post<ApiResponse<{ likes: number }>>(`/api/posts/${id}/like`)
    }
} 